package edu.cuit.zhuyimeng.flight.controller.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.jackson.Jacksonized;
import org.joda.time.YearMonthDay;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.time.MonthDay;

/**
 * 查询航班DTO
 */
@Data
@Schema(description = "查询航班DTO")
public class QueryFlightDTO {

    /**
     * 出发城市
     */
    @NotBlank(message = "出发城市不能为空")
    @Schema(description = "出发城市", example = "成都")
    private String deployCity;

    /**
     * 目的城市
     */
    @NotBlank(message = "目的城市不能为空")
    @Schema(description = "目的城市", example = "北京")
    private String destCity;

    /**
     * 航班时间
     */
    @NotNull(message = "航班时间不能为空")
    @Schema(description = "航班时间（单位: 日）", example = "2024-04-13")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate flightDate;

    @JsonIgnore
    @Schema(hidden = true)
    public String getCacheKey() {
        return flightDate.toString() + "-" + deployCity + "-" + destCity;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {

        private String deployCity;
        private String destCity;
        private LocalDate flightDate;

        public Builder deployCity(String deployCity) {
            this.deployCity = deployCity;
            return this;
        }

        public Builder destCity(String destCity) {
            this.destCity = destCity;
            return this;
        }

        public Builder flightDate(LocalDate flightDate) {
            this.flightDate = flightDate;
            return this;
        }

        public QueryFlightDTO build() {
            QueryFlightDTO queryFlightDTO = new QueryFlightDTO();
            queryFlightDTO.setFlightDate(flightDate);
            queryFlightDTO.setDestCity(destCity);
            queryFlightDTO.setDeployCity(deployCity);
            return queryFlightDTO;
        }
    }

}
